<template>
  <tl-sub-page :render="render" ref="drawerRef" :visible.sync="visible" :with-header="false" class="tl-drawer" :modal-append-to-body="true" :close-on-press-escape="false" :append-to-body="true" size="95%" @open="open" @close="close">
    <div class="mpm-project-container">
      <div class="mpm-project-header">
        <div class="info">
          <img src="/static/images/paojectManager/mpmriskheader.png" class="logo" alt="项目问题" style="width:55px;height:55px" />

          <div class="content" :title="model.projectname">
            <p>
              <b>{{ model.projectname + '-' }}</b>
              <b>项目风险</b>
            </p>
            <p class="light">
              <span>申请人：{{ model.username + '【' + model.usercode + '】' }}</span>
              <span v-if="model.createon">创建时间：{{ formatDate(model.createon) }}</span>
              <span v-else>创建时间：{{ formatDate(new Date()) }}</span>
            </p>
          </div>
        </div>
        <div class="toolbar">
          <el-button type="danger" icon="el-icon-close" circle @click="doCancelEdit"></el-button>
        </div>
      </div>
      <div class="mpm-project-nav" :style="{ height: mainHeight + 'px' }">
        <ul class="nav-list">
          <template v-for="item in navList">
            <li :key="item.code" :class="item.on ? 'on' : ''" @click="clickNav(item.code)" v-show="!(item.code === 'feedback' && model.state !== 9)" style="cursor: pointer;clear: both">
              <span style="float: left;width: 150px">{{ item.name }}</span>
              <span style="float: left;">
                <i v-if="item.count > 0">{{ item.count }}</i>
                <label v-if="item.flag">{{ item.flag }}</label>
              </span>
            </li>
          </template>
        </ul>
      </div>
      <div class="mpm-project-main" :style="{ height: mainHeight + 'px' }">
        <el-scrollbar class="mpm-project-main-container" id="sdMainContainer">
          <div style="padding: 0 10px">
            <el-form class="tl-form" ref="form" :model="model" :rules="rules" label-width="150px" :disabled="disableEditSubmit">
              <a id="basic" class="step-position">&nbsp;</a>
              <div class="tl-form-line-title">
                风险详情
              </div>
              <el-row :gutter="0">
                <el-col :span="12">
                  <el-form-item label="关联里程碑/任务" prop="relateobject">
                    <el-select v-model="model.relateobject" :disabled="disableSave" placeholder="请选择关联里程碑/任务" clearable @change="doChangeRelate">
                      <el-option v-for="item in codeModel.sdMilepostOrTaskList" :key="item.code" :label="item.name" :value="item.code" />
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="里程碑名称" prop="objectname" v-if="model.relateobject !== '2'">
                    <el-input v-model="model.objectname" :disabled="true" class="tl-ref-selector" :class="{ disabled: dodisabled }">
                      <el-button slot="append" type="primary" icon="el-icon-search" @click="openSdProjectMilepostDialog" :disabled="dodisabled"></el-button>
                    </el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="任务名称" prop="objectname" v-if="model.relateobject === '2'">
                    <el-input v-model="model.objectname" :disabled="true" class="tl-ref-selector" :class="{ disabled: dodisabled }">
                      <el-button slot="append" type="primary" icon="el-icon-search" @click="openSdProjectTaskDialog" :disabled="dodisabled"></el-button>
                    </el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="12">
                  <el-form-item label="风险责任人" prop="responsible" v-if="model.responsiblecode !== null && model.responsiblecode !== undefined && model.responsiblecode !== ''">
                    <tl-ref-stakeholder v-model="model.responsiblecode" @confirm="addConfirm" :initDisplayData.sync="model.responsible" fieldKey="usercode" :externalSelectedRowKeys="model.responsiblecode" title="选择风险责任人" :externalQueryParam="externalQueryParam" :isSingleSelect="true"></tl-ref-stakeholder>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="责任人工号" prop="responsiblecode" v-if="model.responsiblecode !== null && model.responsiblecode !== undefined && model.responsiblecode !== ''">
                    <el-input v-model="model.responsiblecode" :disabled="true"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="12">
                  <el-form-item label="风险登记日期" prop="riskdate" :rules="rules.validateRequire">
                    <el-date-picker v-model="model.riskdate" type="date" placeholder="风险登记日期" :disabled="disableSave" value-format="yyyy-MM-dd"></el-date-picker>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="风险性质" prop="riskproperty" :rules="rules.validateRequire">
                    <!-- <el-input v-model="model.riskproperty"></el-input> -->
                    <el-select v-model="model.riskproperty" :disabled="disableSave">
                      <el-option v-for="item in codeModel.riskPropertyList" :key="item.code" :label="item.name" :value="item.code"></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-row>
                  <el-col :span="24">
                    <el-form-item label="风险描述" prop="riskdescription" :rules="rules.lengthRequire">
                      <el-input v-model="model.riskdescription" :disabled="disableSave" type="textarea" :rows="3" placeholder="请输入对风险的详细描述" maxlength="1000" show-word-limit></el-input>
                    </el-form-item>
                  </el-col>
                </el-row>
              </el-row>
              <el-row>
                <el-col :span="24">
                  <el-form-item label="风险措施" prop="riskmeasure" :rules="rules.lengthRequire">
                    <el-input v-model="model.riskmeasure" type="textarea" :disabled="disableSave" :rows="3" placeholder="请输入针对该风险的具体应对措施" maxlength="1000" show-word-limit></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="24">
                  <el-form-item label="备注" prop="description">
                    <el-input v-model="model.description" type="textarea" :disabled="disableSave" :rows="3"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <a id="asses" class="step-position">&nbsp;</a>
              <div class="tl-form-line-title">
                风险评估
              </div>
              <el-row>
                <el-col :span="12">
                  <el-form-item label="风险可能性" prop="riskprobability" :rules="rules.validateRequire">
                    <el-select v-model="model.riskprobability" :disabled="disableSave" placeholder="请选择风险可能性">
                      <el-option v-for="item in codeModel.riskProbabilityList" :key="item.code" :label="item.name" :value="item.code"></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="风险影响程度" prop="riskinfluencelevel" :rules="rules.validateRequire">
                    <el-select v-model="model.riskinfluencelevel" :disabled="disableSave" placeholder="请选择风险影响程度">
                      <el-option v-for="item in codeModel.riskInfluenceLevelList" :key="item.code" :label="item.name" :value="item.code"></el-option>
                    </el-select>
                  </el-form-item>
                </el-col> </el-row
              ><el-row>
                <el-col :span="12">
                  <el-form-item label="风险等级" prop="disprisklevel">
                    <el-input v-bind:value="this.model.disprisklevel" placeholder="根据影响程度和可能性计算" v-bind:class="classRiskLevel" :disabled="true"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>

              <el-row>
                <el-col :span="24">
                  <el-form-item label="风险影响评估" prop="influencequantization" :rules="rules.lengthRequire">
                    <el-input v-model="model.influencequantization" placeholder="请输入对成本、进度、范围等的量化描述" :disabled="disableSave" type="textarea" :rows="3"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <!--审核完成时显示所有的风险反馈信息-->
              <div v-if="!isAdd && model.state === 9">
                <a id="feedback" class="step-position">&nbsp;</a>
                <div class="tl-form-line-title">
                  风险反馈
                </div>
                <el-row>
                  <el-col :span="12">
                    <el-form-item label="措施计划完成日期" prop="riskmeasuredue" class="risk-date">
                      <el-date-picker v-model="model.riskmeasuredue" type="date" placeholder="风险措施计划完成日期" value-format="yyyy-MM-dd"></el-date-picker>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="风险趋势" prop="risktrend">
                      <el-input v-model="model.disprisktrend"></el-input>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="12">
                    <el-form-item label="风险责任人" prop="responsible">
                      <el-input v-model="model.responsible"></el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="风险责任人工号" prop="responsiblecode">
                      <el-input v-model="model.responsiblecode"></el-input>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="24">
                    <el-form-item label="反馈响应" prop="feedback">
                      <el-input v-model="model.feedback" type="textarea" :rows="5"></el-input>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row> </el-row>
              </div>
              <a id="apply" class="step-position">&nbsp;</a>
              <div class="tl-form-line-title">
                申请信息
              </div>
              <el-row>
                <el-col :span="12">
                  <el-form-item label="申请人姓名" prop="username" :rules="rules.validateRequire">
                    <tl-ref-user v-model="model.username" :initDisplayData.sync="model.username" dataType="code" :disabled="true" :singleSelect="true"></tl-ref-user>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="申请人工号" prop="usercode">
                    <el-input v-model="model.usercode" :disabled="true"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="12">
                  <el-form-item label="所属部门" prop="deptname" :rules="rules.validateRequire">
                    <tl-ref-dept v-model="model.deptname" :initDisplayData.sync="model.deptname" :disabled="true" dataType="code" nameType="fullname" :singleSelect="true"></tl-ref-dept>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="所属公司" prop="orgname">
                    <el-input v-model="model.orgname" :disabled="true"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>

              <el-row>
                <el-col :span="12">
                  <el-form-item label="提交日期" prop="submitdate">
                    <el-date-picker v-model="model.submitdate" type="date" placeholder="date()" value-format="yyyy-MM-dd" :disabled="true"></el-date-picker>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="状态" prop="state">
                    <el-select v-model="model.state" filterable clearable :disabled="true" placeholder="开立">
                      <el-option v-for="item in codeModel.stateList" :key="item.code" :label="item.name" :value="parseInt(item.code)" />
                    </el-select>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-form>
            <div slot="footer" class="dialog-footer" style="float: right; margin-top: 10px">
              <el-button type="primary" @click="doSubmitEdit" :loading="saveLoading" v-if="!disableEditSubmit" :disabled="disableSave"><svg-icon icon-class="save" />保存</el-button>
              <el-button type="primary" @click="doAddApproval" :loading="submitLoading" v-if="!disableEditSubmit" :disabled="disableSave"><svg-icon icon-class="send" />提交审批</el-button>
              <tl-attachment ref="attachmentRef" sourceType="GpmProjectRisk" :sourceId="model.id" :disabled="disableAttachment" :editable="stateEdit">
                <el-button type="primary" :disabled="disableAttachment" icon="el-icon-paperclip" @click="$refs.attachmentRef.openUploadDialog()">{{ this.$refs.attachmentRef ? this.$refs.attachmentRef.btnTitle : '' }} [{{ this.$refs.attachmentRef ? (this.$refs.attachmentRef.fileList.length > 0 ? this.$refs.attachmentRef.fileList.length : this.$refs.attachmentRef.fileCount) : 0 }}] </el-button>
              </tl-attachment>
              <el-button type="primary" @click="$refs.history.visible = true" :disabled="disableApprovalHistory"><svg-icon icon-class="list" />审批历史</el-button>
              <!-- <el-button type="primary" @click="doDelApproval" :loading="delApprovalLoading" v-if="!disableEditSubmit" :disabled="disableDelApproval"><svg-icon icon-class="undo" />取消审批</el-button> -->
            </div>
          </div>
        </el-scrollbar>
      </div>
    </div>

    <tl-approval-history ref="history" sourceType="GpmProjectRisk" :sourceId="model.id" />
    <tlsd-project-milepost-ref ref="sdProjectMilepostRef" @confirm="getSdProjectMilepostData" :isSingleSelect="true" :externalQueryParam="externalQueryParamForMilepost" :viewAllMilePost="true"></tlsd-project-milepost-ref>
    <tlsd-project-task-ref ref="sdProjectTaskRef" @confirm="getSdProjectTaskData" :isSingleSelect="true" :externalQueryParam="externalQueryParamForTask"></tlsd-project-task-ref>
  </tl-sub-page>
</template>

<script>
/** mixins */
import { mixin_approval_edit_edit } from '../../../mixins/mixin_approval_edit'
import tlsdProjectMilepostRef from '@/views/gpm/gpmProjectMilepost/refList'
import tlsdProjectTaskRef from '@/views/gpm/gpmProjectTask/refList'
import tlRefStakeholder from '../gpmProjectStakeholder/refList'
/** 子组件 */
/** 工具类 */
import { putAction, getAction, postAction, deleteAction } from '@tapui/utils/http'
import { formatDate } from '@tapui/utils/date'
import { validateNull } from '@tapui/utils/validate'
/** VUE配置 */
export default {
  mixins: [mixin_approval_edit_edit],
  components: { tlsdProjectMilepostRef, tlsdProjectTaskRef, tlRefStakeholder },
  data() {
    return {
      moduleTitle: '项目风险',
      urlPrefix: '/sd/projectRisk/',
      url: {
        // 额外的url
        riskLevelMatrixUrl: '/sd/projectRisk/riskLevelMatrix'
      },
      addRules: {
        // 输入框通用校验
        lengthRequire: [{ pattern: '.{1,}', required: 'true', message: '输入内容过短', trigger: 'change' }, { whitespace: true, required: 'true', message: '输入内容不能为空格', trigger: 'change' }]
      },
      // 风险评估矩阵
      riskLevelMatrix: '',
      disprisklevel: '',
      isAdd: false,
      // 抽屉组件
      mainHeight: 700,
      navList: [{ name: '风险详情', on: true, code: 'basic' }, { name: '风险评估', on: false, code: 'asses' }, { name: '风险反馈', on: false, code: 'feedback' }, { name: '申请信息', on: false, code: 'apply' }],
      mainScrollElement: null,
      externalQueryParam: {
        qry_projectcode: this.projectinfo.projectcode, // 项目编号
        qry_stakeholdercategory: '1', // 表示类别为内部人员
        qry_enabled: '1' // 表示有效人员
      },
      externalQueryParamForMilepost: {
        qry_projectcode: this.projectinfo.projectcode, // 项目编号
        qry_enabled: '1' // 表示有效
      },
      externalQueryParamForTask: {
        qry_projectcode: this.projectinfo.projectcode, // 项目编号
        qry_enabled: '1' // 表示有效
      }
    }
  },
  // 传入projectinfo
  props: {
    projectinfo: {
      type: Object,
      default: () => {
        return {}
      }
    },
    render: {
      default: 'el-drawer',
      type: String
    }
  },
  computed: {
    // 当风险可能性和风险影响程度 任意一个更新后 拼串返回
    riskprobabilityAndriskinfluencelevel() {
      return `${this.model.riskprobability}|${this.model.riskinfluencelevel}`
    },
    classRiskLevel: function() {
      let res = ''
      switch (this.model.risklevel) {
        case 0:
          res = 'low-level'
          break
        case 1:
          res = 'middle-level'
          break
        case 2:
          res = 'high-level'
          break
      }
      return res
    },
    dodisabled() {
      return (this.isAdd === false && this.disableEditSubmit === true) || this.fromApproval === '1'
    }
  },
  watch: {
    // riskprobabilityAndriskinfluencelevel 更新后 将风险等级 risklevel，根据data()里的map 返回对应的 低中高 0 1 2
    riskprobabilityAndriskinfluencelevel(after, before) {
      const [newProbability, newInfluenceLevel] = after.split('|')
      if (newProbability !== 'undefined' && newInfluenceLevel !== 'undefined') {
        this.$set(this.model, 'risklevel', this.riskLevelMatrix[newProbability][newInfluenceLevel])
        // 这个之后改成codemodellist获取
        let temp = this.codeModel.riskLevelList.filter((element) => {
          return parseInt(element.code) === this.model.risklevel
        })
        this.disprisklevel = temp[0].name
        this.$set(this.model, 'disprisklevel', temp[0].name)
      }
    }
  },
  methods: {
    // 重写保存方法，去除必填校验
    doSubmitEdit() {
      if (!this.beforeSubmit()) {
        return
      }
      if (this.isAdd) {
        this.doAdd()
      } else {
        this.doEdit()
      }
    },
    assignDefaultValue() {
      if (this.isAdd) {
        if (this.codeModel.flowidList && this.codeModel.flowidList.length > 0) {
          this.$set(this.model, 'flowid', parseInt(this.codeModel.flowidList[0].id))
        }

        this.$set(this.model, 'orgcode', this.org.code)
        this.$set(this.model, 'disporgcode', this.org.name)
        this.$set(this.model, 'orgname', this.org.name)

        this.$set(this.model, 'deptcode', this.dept.code)
        this.$set(this.model, 'deptname', this.dept.fullname)
        this.$set(this.model, 'usercode', this.user.code)
        this.$set(this.model, 'username', this.user.name)
        this.$set(this.model, 'docdate', new Date())
        this.$set(this.model, 'submitdate', new Date())
        this.$set(this.model, 'state', 0)

        this.$set(this.model, 'riskdate', new Date())
      }
    },
    /** 新增状态下把项目信息自动填写到单据中 **/
    setProjectInfo() {
      this.$set(this.model, 'projectid', this.projectinfo.id)
      this.$set(this.model, 'deptcommoncode1', this.projectinfo.deptcommoncode1)
      this.$set(this.model, 'projectlevel', this.projectinfo.projectlevel)
      this.$set(this.model, 'dispprojectlevel', this.projectinfo.dispprojectlevel)
      this.$set(this.model, 'projectname', this.projectinfo.projectname)
      this.$set(this.model, 'projectcode', this.projectinfo.projectcode)
      this.$set(this.model, 'projectmanager', this.projectinfo.projectmanager)
      this.$set(this.model, 'projectmanagercode', this.projectinfo.projectmanagercode)
    },
    // addNavi() {
    //         this.navList.splice(2, 0, { name: "风险反馈", on: false, code: "feedback" })
    // },
    /** 抽屉组件必有 **/
    resizeHandler() {
      this.mainHeight = document.body.getBoundingClientRect().height - 100 - (this.isApproval ? 110 : 0)
    },
    /** 抽屉组件必有 **/
    doCancelEdit() {
      this.visible = false
      this.$emit('close')
      this.$emit('refresh')
    },
    /** 抽屉组件必有 **/
    formatDate(date) {
      return formatDate(new Date(date), 'yyyy-MM-dd')
    },
    /** 点击左侧导航，抽屉组件必有 **/
    clickNav(code) {
      this.navList.forEach((m) => {
        if (m.code === code) {
          m.on = true
        } else {
          m.on = false
        }
      })
      let element = document.getElementById(code)
      if (element === null) return
      let goY = element.getBoundingClientRect().y - 75
      this.mainScrollElement.scrollTop += goY
    },
    /** 页面滚动时，动态改变左侧导航选中的元素，抽屉组件必有 **/
    onMainScroll() {
      const scrollFun = () => {
        const currentEl = [...this.$el.getElementsByClassName('step-position')].find((item) => item.getBoundingClientRect().y >= 0)
        const code = currentEl ? currentEl.id : ''
        this.navList.forEach((m) => (m.on = m.code === code))
      }
      this.mainScrollElement.removeEventListener('scroll', scrollFun)
      this.mainScrollElement.addEventListener('scroll', scrollFun)
    },
    /** 抽屉组件必重写，主要为了执行resizeHandler方法、给mainScrollElement赋值，并添加监听事件，不要直接复制该方法 **/
    open() {
      this.model = {}
      this.resizeHandler()
      this.$nextTick(() => {
        this.$refs.form.clearValidate()
        if (this.isAdd === true) {
          this.title = '新增' + this.moduleTitle
          // 需要添加重复判断
          if (this.$store.getters.param.isAvoidRepeat === true) {
            this.queryBillUid()
          }
          if (this.isQueryInitData === true) {
            // 后台进行数据初始化
            this.queryInitData().then((_) => {
              this.assignDefaultValue()
              this.loaded()
            })
          } else {
            // 前台进行数据初始化
            this.$set(this.model, 'enabled', 1)
            this.$set(this.model, 'sortcode', 0)
            this.assignDefaultValue()
            this.loaded()
          }
          // 判断是否可以将项目信息自动填写在单据中
          if (this.projectinfo.id) {
            this.setProjectInfo(this.projectinfo)
          }
        } else if (this.disableEditSubmit === false) {
          this.title = '编辑' + this.moduleTitle
          this.queryData(this.id).then((_) => {
            this.loaded()
          })
        } else {
          this.title = '查看' + this.moduleTitle
          this.queryData(this.id).then((_) => {
            this.loaded()
          })
        }
        this.mainScrollElement = this.$el.querySelector('#sdMainContainer .el-scrollbar__wrap')
        this.onMainScroll()
      })
    },
    doAddApproval() {
      let that = this
      that.submitLoading = true
      this.$tap.confirm('确定提交审批吗？提交后，单据内容不可修改！').then((_) => {
        this.$refs.form.validate(async (valid) => {
          if (valid) {
            let saveresult = await that.addBase()
            if (saveresult) {
              this.saveLoading = true
              putAction(this.url.submit, this.model)
                .then((res) => {
                  if (res.success) {
                    that.queryData(that.model.id).then((_) => {
                      that.loaded()
                      that.saveLoading = false
                      that.submitLoading = false
                    })
                    that.$tap.alert('提交审批成功', 'success')
                  } else {
                    that.$tap.alert(res.message, 'warning')
                    that.saveLoading = false
                    that.submitLoading = false
                  }
                })
                .catch((err) => {
                  that.saveLoading = false
                  that.submitLoading = false
                })
            }
          } else {
            that.submitLoading = false
            that.$tap.alert('按要求填写表单数据项，包括必填项，数据格式等')
          }
        })
      })
    },
    loaded() {
      // 页面加载完毕执行
      if (!this.isAdd && this.model.docno) {
        this.title = this.title + `（单据编号：${this.model.docno}）`
      }
    },
    // 提交审批时初始化提交日期
    beforeDelApproval() {
      this.$set(this.model, 'submitdate', new Date())
      return true
    },

    // 获取风险等级矩阵
    getRiskLevelMatrix() {
      getAction(this.url.riskLevelMatrixUrl, '').then((res) => {
        if (res.success) {
          let matrix = JSON.parse(res.result.riskLevelMatrix)
          this.$set(this, 'riskLevelMatrix', matrix)
        }
      })
    },
    openSdProjectMilepostDialog() {
      if (this.$tap.validate.validateNull(this.model.relateobject)) {
        this.$tap.alert('请先选择关联里程碑/任务', 'warning')
        return
      }
      this.$refs.sdProjectMilepostRef.visible = true
    },
    getSdProjectMilepostData(selectedRows, selectedKeys, selectedValues) {
      this.$set(this.model, 'objectcode', selectedRows.milepostcode)
      this.$set(this.model, 'objectname', selectedRows.milepostname)
      this.$set(this.model, 'responsiblecode', selectedRows.responsiblecode)
      this.$set(this.model, 'responsible', selectedRows.responsible)
    },
    openSdProjectTaskDialog() {
      if (this.$tap.validate.validateNull(this.model.relateobject)) {
        this.$tap.alert('请先选择关联里程碑/任务', 'warning')
        return
      }
      this.$refs.sdProjectTaskRef.visible = true
    },
    getSdProjectTaskData(selectedRows, selectedKeys, selectedValues) {
      this.$set(this.model, 'objectcode', selectedRows.id)
      this.$set(this.model, 'objectname', selectedRows.taskname)
      this.$set(this.model, 'responsiblecode', selectedRows.responsiblecode)
      this.$set(this.model, 'responsible', selectedRows.responsible)
    },
    // 人员选择后赋值
    addConfirm(rows, keys, values) {
      this.$set(this.model, 'responsiblecode', keys)
      this.$set(this.model, 'responsible', values)
    },
    doChangeRelate(data) {
      if (validateNull(data)) {
        this.$set(this.model, 'objectname', null)
        this.$set(this.model, 'responsiblecode', null)
        this.$set(this.model, 'responsible', null)
      }
    }
  },
  created() {
    this.getRiskLevelMatrix()

    // 抽屉组件必有
    window.addEventListener('resize', this.resizeHandler)
  },
  destroyed() {
    // 抽屉组件必有
    window.removeEventListener('resize', this.resizeHandler)
  }
}
</script>
<style lang="scss" scoped>
.risk-date /deep/ .el-form-item__label {
  padding: 0 6px 0 0;
}

.tl-drawer /deep/ .el-drawer__body {
  overflow: unset;
}

$riskLevels: high, middle, low;
$riskColors: #ff6363, #ffe119, #bfef45;
//for 循环 根据风险低中高 匹配颜色和字体样式
@for $i from 1 through 3 {
  .#{nth($riskLevels,$i)}-level /deep/ .el-input__inner {
    background-color: nth($riskColors, $i) !important;
    //背景红色 则加粗
    @if $i == 1 {
      font-weight: bold;
    }
    color: #303133 !important;
  }
}
</style>
